package com.example.dubbo.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dubbo.api.dto.CommodityDTO;
import com.example.dubbo.api.enums.RspStatusEnum;
import com.example.dubbo.api.response.ObjectResponse;
import com.example.dubbo.storage.dao.StorageTblDao;
import com.example.dubbo.storage.entity.StorageTblEntity;
import com.example.dubbo.storage.service.StorageTblService;
import org.springframework.stereotype.Service;



/**
 * @author Liyuhang
 */
@Service("storageTblService")
public class StorageTblServiceImpl extends ServiceImpl<StorageTblDao, StorageTblEntity> implements StorageTblService {

    @Override
    public ObjectResponse decreaseStorage(CommodityDTO commodityDTO) {
        int storage = baseMapper.decreaseStorage(commodityDTO.getCommodityCode(), commodityDTO.getCount());
        ObjectResponse<Object> response = new ObjectResponse<>();
        if (storage > 0){
            response.setStatus(RspStatusEnum.SUCCESS.getCode());
            response.setMessage(RspStatusEnum.SUCCESS.getMessage());
            return response;
        }

        response.setStatus(RspStatusEnum.FAIL.getCode());
        response.setMessage(RspStatusEnum.FAIL.getMessage());
        return response;
    }

}